package com.xrs.xrseducation.user.controller;


import com.xrs.xrseducation.user.entity.User;
import com.xrs.xrseducation.user.jsonUtils.UserJson;
import com.xrs.xrseducation.user.service.IUserService;
import com.xrs.xrseducation.user.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2020-09-21
 */
@RestController
@RequestMapping("/user/user")
public class UserController {
    @Autowired
    private IUserService userServiceImpl;

    //查询所有
    @GetMapping("queryall.do")
    public UserJson queryall(Integer page,Integer limit){
        return userServiceImpl.queryall(page,limit);
    }

    //添加用户
    @PostMapping("add.do")
    public UserJson add(User user){
        return userServiceImpl.add(user);
    }

    //修改用户
    @PostMapping("update.do")
    public UserJson update(User user){
        UserJson userJson=new UserJson();
        boolean b=userServiceImpl.updateById(user);
        if(b){
            userJson.setCode(0);
        }else{
            userJson.setCode(1);
        }
        return userJson;
    }

    //删除用户
    @GetMapping("delete.do")
    public UserJson delete(User user){
        UserJson userJson=new UserJson();
        boolean b=userServiceImpl.removeById(user.getUid());
        if(b){
            userJson.setCode(0);
        }else{
            userJson.setCode(1);
        }
        return userJson;
    }

}
